package com.ruoyi.web.controller.office;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ruoyi.common.core.domain.CxSelect;
import com.ruoyi.framework.interceptor.anno.MyPermissions;
import com.ruoyi.office.bean.bo.ChopInfoBO;
import com.ruoyi.office.bean.vo.dto.ChopInfoCheckDTO;
import com.ruoyi.office.bean.vo.qo.ChopInfoQO;
import com.ruoyi.office.domain.ChopInfo;
import com.ruoyi.office.domain.ChopType;
import com.ruoyi.office.service.IChopInfoService;
import com.ruoyi.office.service.IChopTypeService;
import com.ruoyi.web.controller.biz.data.IdName;
import com.ruoyi.web.controller.core.impl.BaseBQCtrollerExImpls;
import com.ruoyi.web.controller.office.data.ChopStatus;
import com.ruoyi.web.controller.office.data.SealTypes;

/**
 * 信息
 * 
 * @author riverbo
 */
@MyPermissions("用章审核信息")
@Controller
@RequestMapping("office/chopinfo/record")
public class ChopInfoRecordController
		extends BaseBQCtrollerExImpls<IChopInfoService, ChopInfo, ChopInfoBO, ChopInfoQO, ChopInfoCheckDTO> {

	@Autowired
	private IChopTypeService chopTypeService;
	
	@Override
	public String query(ModelMap mmap) throws Exception {
		//
		List<CxSelect> lsChopType = getChopTypeData();
		mmap.put("ctData", lsChopType);
		//
		List<IdName> sealTypes = SealTypes.getList();
		mmap.put("sealTypes", sealTypes);
		//
		List<IdName> chopStatus = ChopStatus.getList();
		mmap.put("chopStatus", chopStatus);
		mmap.put("curStatus", 1);
		//
		return super.query(mmap);
	}
	
	@Override
	public String view(@PathVariable("id") Long id, ModelMap mmap) throws Exception {
		List<CxSelect> lsChopType = getChopTypeData();
		mmap.put("ctData", lsChopType);
		//
		List<IdName> sealTypes = SealTypes.getList();
		mmap.put("sealTypes", sealTypes);
		//
		List<IdName> chopStatus = ChopStatus.getList();
		mmap.put("chopStatus", chopStatus);
		//
		return super.view(id, mmap);
	}

	@Override
	public String check(@PathVariable("id") Long id, ModelMap mmap) throws Exception {
		List<CxSelect> lsChopType = getChopTypeData();
		mmap.put("ctData", lsChopType);
		//
		List<IdName> sealTypes = SealTypes.getList();
		mmap.put("sealTypes", sealTypes);
		//
		List<IdName> chopStatus = ChopStatus.getList();
		mmap.put("chopStatus", chopStatus);
		//
		String rst = super.check(id, mmap);
		int curAgree = 1;
		ChopInfoBO b = (ChopInfoBO)mmap.get("vo");
		if (b != null && b.getStatus() != null) {
			if (b.getStatus().equals("3")) {
				curAgree = 0;
			}
		}
		mmap.put("curAgree", curAgree);
		return rst;
	}

	protected List<CxSelect> getChopTypeData() {
		List<CxSelect> cxList = new ArrayList<CxSelect>();
		{
			Map<Integer, List<ChopType>> map = chopTypeService.getGroupMapList();
			List<ChopType> lsChopType = chopTypeService.getGroupRoot();
			for (ChopType u : lsChopType) {
				CxSelect cxSelectRoot = new CxSelect(String.valueOf(u.getChopTypeId()), u.getChopTypeName());
				List<CxSelect> subList = new ArrayList<CxSelect>();
				//
				List<ChopType> lsLt = map.get(u.getChopTypeId());
				if (lsLt != null) {
					for (ChopType lt : lsLt) {
						subList.add(new CxSelect(String.valueOf(lt.getChopTypeId()), lt.getChopTypeName()));
					}
				}
				cxSelectRoot.setS(subList);
				//
				cxList.add(cxSelectRoot);
			}
		}
		return cxList;
	}

}